<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="zh-cn" style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?=VIEW_TITLE?></title>
    <link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">

    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
</head>
<body>
<?php $this->load->view('simple_header.php');?>
<div class="container-fluid" style="margin-bottom:100px;">
    <div id="main_div" class="row">
        <div class="title" style="line-height:70px;font-size:36px;text-align: center;"><?=VIEW_TITLE?></div>
        <div class="col-sm-4 col-md-4">
        </div>
        <div class="col-sm-4 col-md-4" id="page_1">
            <form class="form-horizontal" method="post" onsubmit="return false;">
                <div class="form-group">
                    <div class="col-sm-12 col-md-12">
                        <div class="input-group">
                            <input type="text" class="form-control" id="username" name="username"
                                   placeholder="请输入手机号或者邮箱">
                            <span class="input-group-btn">
                                <button id="btn_getCode" class="btn btn-primary" type="button" onclick="getCode()">
                                    获取验证码
                                </button></span>
                        </div>
                        <!--                    <input type="text" class="form-control" id="username" placeholder="请输入手机号或者邮箱" name="username">-->
                        <input style="margin-top: 10px" type="text" class="form-control" id="code"
                               placeholder="请输入验证码" name="code">
                        <input style="margin-top: 10px" type="password" class="form-control" id="password"
                               placeholder="请输入密码" name="password">
                        <!--                    <input style="margin-top: 10px" type="rpassword" class="form-control" id="rpassword"-->
                        <!--                           placeholder="请再次输入密码" name="rpassword">-->
                        <input style="margin-top: 10px" type="text" class="form-control" id="invitecode"
                               placeholder="请输入邀请码" name="invitecode">
                        <input hidden="hidden" value="" name="p_token">
                    </div>
                </div>
                <div style="text-align: center;"><input type="checkbox" id="tiaokuang"><a href="javascript:read()">我已阅读并同意《译员服务协议》</a>
                </div>
                <div class="form-group">
                    <div class="col-sm-12 col-md-12" style="margin-top: 10px">
                        <button class="btn btn-primary btn-block" onclick="register()">立即注册</button>
                    </div>
                </div>
            </form>
            <div class="alert alert-danger" role="alert" id="warn" style="display: none;"></div>
        </div>
        <div class="col-sm-4 col-md-4" id="page_2" style="display: none;text-align: center;">
            <h3>恭喜您,注册成功!</h3>
            <a style="font-size: 16px" class="" href="<?php echo site_url('/admin/login');?>">立即登录</a>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">《译员服务协议》</h4>
            </div>
            <div class="modal-body">
                <div style="overflow-y: scroll;max-height: 400px;">
                    <?php $this->load->view('fuwuxieyi.php');?>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">已阅读</button>
                <!--                <button type="button" class="btn btn-primary">Save changes</button>-->
            </div>
        </div>
    </div>
</div>

<div class="hidden-xs">
<?php
$this->load->view('footer.php');
?>
</div>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<?php echo base_url('/assets/'); ?>js/jquery.JPlaceholder.js"></script>
<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
<script>
    var w_width = document.documentElement.clientWidth;
    var w_height = document.documentElement.clientHeight;
    var main_div_height = w_height - 300;
    $('#main_div').height(main_div_height + 'px');
    $('.title').css('margin-top', main_div_height * 0.1 + 'px');
    var is_getCode = 0;
    function Isyx(yx) {
        var reyx = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        return (reyx.test(yx));
    }
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
    //    if(!myreg.test($("#phone").val()))
    //    {
    //        alert('请输入有效的手机号码！');
    //        return false;
    //    }

    function register() {
        var username = $('#username').val();
        var password = $('#password').val();
        var rpassword = $('#rpassword').val();
        var code = $('#code').val();
        var invitecode = $('#invitecode').val();
        if (username == '' || password == '' || code == '' || invitecode == '') {
//            alert('账号密码不能留空!');
            $('#warn').text('内容不能留空!');
            $('#warn').show();
            return false;
        }
//        if(password != rpassword){
//            $('#warn').text('两次输入的密码不相同!');
//            $('#warn').show();
//            return false;
//        }
        if (!myreg.test(username) && !Isyx(username)) {
            $('#warn').text('请确认账户名为手机号码或者邮箱地址!');
            $('#warn').show();
            return false;
        }
//        if (is_getCode == 0) {
//            alert('请先获取验证码!');
//            return false;
//        }
        if (!$('#tiaokuang').is(':checked')) {
            alert('请先阅读《专业翻译条款》,并且选择确认!');
            return false;
        }
        $.ajax({
            url: '<?php echo site_url('/Admin/registerAttestation')?>',
            type: 'post',
            dataType: 'json',
            data: {
                username: username,
                password: password,
                code: code,
                invitecode: invitecode
//                token: '<?php //echo $token?>//'
            },
            success: function (data) {
                console.log(data);
                var warn_text = data['msg'];
                if (data.code == 5) {
                    $('#page_1').hide();
                    $('#page_2').show();
                } else {
                    $('#warn').text(warn_text);
                    $('#warn').show();
                }
            }
        });
    }
    function read() {
        $('#myModal').modal('show');
    }

    function getCode() {
        if (is_getCode == 1) {
            alert('请稍后再试!');
            return false;
        }

        var username = $('#username').val();
        if (username == '') {
            $('#warn').text('请先填写手机号码或邮箱地址!');
            $('#warn').show();
            return false;
        }
        if (!myreg.test(username) && !Isyx(username)) {
            $('#warn').text('请确认账户名为手机号码或者邮箱地址!');
            $('#warn').show();
            return false;
        }
        $.ajax({
            url: '<?php echo site_url('/Admin/getCode')?>',
            type: 'post',
            dataType: 'json',
            data: {
                username: username,
                codetype: 1,
                type:'register'
            },
            success: function (data) {
                console.log(data);
                if (data == 1) {
                    is_getCode = 1;
                    $('#btn_getCode').attr('disabled', 'disabled');
                    alert('验证码发送成功,请注意查收!');
                } else if(data == 2) {
                    is_getCode = 0;
//                    $('#btn_getCode').attr('disabled', 'none');
                    alert('验证码发送失败!');
                }else if(data == 3){
                    is_getCode = 0;
//                    $('#btn_getCode').attr('disabled', '');
                    alert('该手机或邮箱已经被使用!');
                }else if(data == 4){
                    alert('该服务正在维修,请稍后再试!');
                }
            }
        });
    }
</script>
</body>
</html>